<?php

/*
 * Following code will list all the game
 */

// array for JSON response
$response = array();


// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// get all game from game table
$result = mysql_query("SELECT *FROM message") or die(mysql_error());

// check for empty result
if (mysql_num_rows($result) > 0) {
    // looping through all results
    // game node
    $response["message"] = array();
    
    while ($row = mysql_fetch_array($result)) {
        // temp user array
        $message = array();
        $message["id"] = $row["id"];
        $message["id_send"] = $row["id_send"];
        $message["id_receive"] = $row["id_receive"];
        $message["is_acept"] = $row["is_accept"];
        $message["id_request"] = $row["id_request"];


        // push single product into final response array
        array_push($response["message"], $message);
    }
    // success
    $response["responseCode"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no game found
    $response["responseCode"] = 0;
    $response["responseMessage"] = "No message found";

    // echo no users JSON
    echo json_encode($response);
}
?>
